package com.sikaryofficial.backend.utils;

import org.apache.commons.compress.utils.Lists;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

/**
 * @author : qinjinyuan
 * @desc : 文件读取工具
 * @date : 2024/04/17 19:11
 */
public class HiSMKFileUtil {

    public static List<String> readExternalTxtFile(String path) {
        Resource resource = new FileSystemResource(path);
        List<String> lines = Lists.newArrayList();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to read external txt file", e);
        }
        return lines;
    }
}
